package com.adeaz.sdk.demo.wow;

import com.adeaz.sdk.demo.MainActivity;

import java.util.ArrayList;
import java.util.List;


public class AdLayerUtil {
    private static final String TAG = AdLayerUtil.class.getSimpleName();
    MainActivity act;
    LoopPager mBannerLoopPager;

    List<AdData> mAdList;

    public AdLayerUtil(MainActivity act, LoopPager mBannerLoopPager) {
        super();
        this.act = act;
        this.mBannerLoopPager = mBannerLoopPager;
        initAdPagerParams();
        bindListener();
    }

    public void initAdPagerParams() {

        // 设置自动轮播间隔时间
        mBannerLoopPager.setDuration(6000);
//		getGdtDa();
    }

    /**
     * 绑定数据
     */
    private void bindListener() {

        // 换页事件
//		mBannerIndicator
//				.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
//
//					@Override
//					public void onPageSelected(int position) {
//						// 上传友盟统计广告展示事件
//						MLog.d(TAG, "adPager onPageSelected arg0:" + position);
//						int location = position % mAdList.size();
//						AdData adData = mAdList.get(location);
//						UmengUtils.reportEvent(act, adData.show);
//					}
//
//					@Override
//					public void onPageScrolled(int arg0, float arg1, int arg2) {
//					}
//
//					@Override
//					public void onPageScrollStateChanged(int arg0) {
//					}
//				});
    }

    /**
     * 加载广告
     */
    public void getGdtDa() {
        //用于存放后台的数据
        mAdList = new ArrayList<>();
        mAdList.add(new AdData("http://113.204.20.22:2001/img/mall/mainad/cf8a86b6-259d-4a57-b5f4-1c6bcb0707f9.jpg"));
        mAdList.add(new AdData("http://113.204.20.22:2001/img/mall/mainad/f3bc9171-917c-4365-ba06-5929c4ab4bae.jpg"));
        mAdList.add(new AdData("http://113.204.20.22:2001/img/mall/mainad/f6c48a59-b83b-4435-9260-8612d57c9596.jpg"));
        mAdList.add(new AdData("http://113.204.20.22:2001/img/mall/mainad/e4f57f86-c6f0-4891-bf7b-56dbba2f6c2c.jpg"));
        mAdList.add(new AdData("http://113.204.20.22:2001/img/mall/mainad/e4f57f86-c6f0-4891-bf7b-56dbba2f6c2c.jpg"));
        mAdList.add(new AdData("http://113.204.20.22:2001/img/mall/mainad/e4f57f86-c6f0-4891-bf7b-56dbba2f6c2c.jpg"));
        mAdList.add(new AdData("http://113.204.20.22:2001/img/mall/mainad/e4f57f86-c6f0-4891-bf7b-56dbba2f6c2c.jpg"));
        mAdList.add(new AdData("http://113.204.20.22:2001/img/mall/mainad/e4f57f86-c6f0-4891-bf7b-56dbba2f6c2c.jpg"));
        mAdList.add(new AdData("http://113.204.20.22:2001/img/mall/mainad/e4f57f86-c6f0-4891-bf7b-56dbba2f6c2c.jpg"));
        mAdList.add(new AdData("http://113.204.20.22:2001/img/mall/mainad/e4f57f86-c6f0-4891-bf7b-56dbba2f6c2c.jpg"));
        mAdList.add(new AdData("http://113.204.20.22:2001/img/mall/mainad/e4f57f86-c6f0-4891-bf7b-56dbba2f6c2c.jpg"));
        initAdapter();
    }

    private void initAdapter() {

        if (mAdList == null)
            mAdList = new ArrayList<>();
        if (mAdList.size() > 1) {
            mBannerLoopPager.setNoTouchScroll(false);
        } else {
            mBannerLoopPager.setNoTouchScroll(true);
        }
//        mBannerLoopPager.setOffscreenPageLimit(mAdList.size());
        mBannerLoopPager.setAdapter(new BannerAdapter(act, mAdList));
//        mBannerLoopPager.setBoundaryCaching(true);
    }

}
